package com.mashen.util;

import java.io.InputStreamReader;
import javax.servlet.http.HttpServletRequest;

import com.mshen.service.model.ImageResponseMessage;
import com.mshen.service.model.TextResponseMessage;
import com.mshen.service.model.WeixinRequest;
import com.thoughtworks.xstream.XStream;

public class MessageUtil {
	public static WeixinRequest getWeixinRequest(HttpServletRequest
			request) throws Throwable{
		XStream xs=new XStream();
		xs.alias("xml", WeixinRequest.class);
		WeixinRequest wxreq=(WeixinRequest)xs.fromXML(
				new InputStreamReader(request.getInputStream(),
				Constant.CHARSET));
		System.out.println(wxreq);
		return wxreq;
	
	}
	
	public static String toXML(TextResponseMessage msg){
		XStream xs=new XStream();
		xs.alias("xml", TextResponseMessage.class);
		String xml=xs.toXML(msg);
		System.out.println(xml);
		return xml;
	}
	public static String toXML(ImageResponseMessage msg){
		XStream xs=new XStream();
		xs.alias("xml", ImageResponseMessage.class);
		String xml=xs.toXML(msg);
		System.out.println(xml);
		return xml;
	}
}
